//
// Created by xili on 2024/8/28 20:26.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int carFleet(int target, vector<int> &position, vector<int> &speed) {
        map<int, int> m;
        int n = position.size();
        for (int i = 0; i < n; i++) {
            m[position[i]] = speed[i];
        }
        stack<float> st;
        for (auto &[p, s]: m) {
            float t = (float) (target - p) / s;
            while (!st.empty() && t >= st.top()) {
                st.pop();
            }
            st.push(t);
        }
        return st.size();
    }
};